﻿using System.Data;
using Dapper;

namespace PoemGame.Query.Dapper
{
    public class PlayerQuery:IPlayerQuery
    {
        private readonly IDbConnection connection;
        
        public PlayerQuery(IDbConnection connection)
        {
            this.connection = connection;
        }
       
        public async Task<PlayerRes?> GetPlayerResAsync(Guid playerId)
        {
            return await connection.GetAsync<PlayerView>(playerId);
        }

        public async Task<IEnumerable<PlayerRes>> GetPlayersByConditionAsync(
            string wherecondition)
        {
            return await connection.GetListAsync<PlayerView>(wherecondition); ;
        }

        public async Task<IEnumerable<PlayerRes>> GetPagedPlayersByConditionAsync(
            int pageindex, int pagesize, string wherecondition, string orderby)
        {
            return await connection.GetListPagedAsync<PlayerView>(
                pageindex,pagesize,wherecondition,orderby); 
        }

        public async Task<long> GetPlayersCountByConditionAsync(string wherecondition)
        {
            return await connection.RecordCountAsync<PlayerView>(wherecondition);
        }
    }
}